package com.own.demo.建筑物;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.own.demo.utils.FileToStringUtils;
import com.own.demo.utils.geo.PoiTypeEnums;
import com.own.demo.utils.geo.buffer.LineBufferImpl;
import org.locationtech.jts.geom.LineString;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class 扣除建筑物 {
    public static int floorHeight=3;
    public static LineBufferImpl defaultBuffer = (LineBufferImpl) PoiTypeEnums.POLYLINE.getBufferUtil();

    public static Map<Integer, List<LineString>> floorMap = new HashMap(1024);
    public static Map<Integer, List<LineString>> floorHeightMap = new HashMap(1024);



    static {
        floorHeightMap.put(-1,new ArrayList<>());
        for(int i=1;i<9;i++){
            floorHeightMap.put(i,new ArrayList());
        }
    }

    public static void main(String[] args) {
        countInfo();
        floorHeightMap.remove(-1);
        JSONArray jsonArrayBuild = new JSONArray(10001);

        File geoZJ = new File("E:\\ownCode\\emg-geojson\\src\\test\\java\\com\\own\\demo\\建筑物\\正方形格子.geojson");
        String geoData = FileToStringUtils.txt2String(geoZJ);
        JSONObject jsonObject=JSONObject.parseObject(geoData);




        扣除建筑物逻辑处理.buildingDel( jsonObject.getJSONArray("features"));
//        String json= JSONObject.toJSONString(jsonArrayBuild);
//        writerFoFile(json,"E:\\ownCode\\UMA\\数据","40米以上的建筑物.json");
    }

    public static void countInfo(){
        File geoZJ = new File("E:\\ownCode\\emg-geojson\\src\\test\\java\\com\\own\\demo\\建筑物\\building2.geojson");
        JSONObject geoData = JSONObject.parseObject(FileToStringUtils.txt2String(geoZJ));

        JSONArray jsonArray = geoData.getJSONArray("features");

        int row=jsonArray.size();

        for (int i = 0; i < row; i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            JSONObject properties = jsonObject.getJSONObject("properties");

            Integer floor = properties.getInteger("Floor");

            JSONObject geometry = jsonObject.getJSONObject("geometry");
            geometry.put("Floor",floor);


            List<LineString> floorArr = floorMap.get(floor);
            if (floorArr == null) {
                floorArr = new ArrayList<>(2024);
                floorMap.put(floor, floorArr);
            }
            floorArr.add(defaultBuffer.getLineStringGeometry(geometry));
        }
        initData();
        System.out.println(floorMap.size());


        int allData=0;
        for (Map.Entry<Integer, List<LineString>> data : floorHeightMap.entrySet()) {
            allData=allData+data.getValue().size();
        }
        System.out.println("总数据："+row+",统计数据："+allData);
        System.out.println("每一层数据量");
        for (Map.Entry<Integer, List<LineString>> data : floorHeightMap.entrySet()) {
            System.out.println("第"+data.getKey()+"层, 数量："+data.getValue().size());
        }
    }

    private static void setMap(int key,List<LineString> jsonArray){
        floorHeightMap.get(key).addAll(jsonArray);
    }

    private static void initData(){
        for (Map.Entry<Integer, List<LineString>> data : floorMap.entrySet()) {
            int floor=data.getKey();
            int height=  floor*floorHeight;
            if(height<40) {
                setMap(-1,data.getValue());
                continue;
            }

            //第一层：
            if(height<=60){
                setMap(1,data.getValue());
                continue;
            }

            if(height<=80){
                setMap(2,data.getValue());
                continue;
            }

            if(height<=100){
                setMap(3,data.getValue());
                continue;
            }

            if(height<=120){
                setMap(4,data.getValue());
                continue;
            }

            if(height<=140){
                setMap(5,data.getValue());
                continue;
            }

            if(height<=160){
                setMap(6,data.getValue());
                continue;
            }

            if(height<=180){
                setMap(7,data.getValue());
                continue;
            }

            if(height<=200){
                setMap(8,data.getValue());
                continue;
            }
        }

    }
}
